package com.lottery;

import java.util.HashSet;
import java.util.Set;

public class LotteryChecker {

    public static int checkPrizeLevel(int[] userRedBalls, int userBlueBall, int[] drawRedBalls, int drawBlueBall) {
        Set<Integer> userRedSet = toSet(userRedBalls);
        Set<Integer> drawRedSet = toSet(drawRedBalls);

        // 计算红球匹配数量
        userRedSet.retainAll(drawRedSet);
        int matchedReds = userRedSet.size();

        // 计算蓝球是否匹配
        boolean isBlueMatched = userBlueBall == drawBlueBall;

        // 判断中奖等级
        if (matchedReds == 6 && isBlueMatched) {
            return 1; // 一等奖
        } else if (matchedReds == 6) {
            return 2; // 二等奖
        } else if (matchedReds == 5 && isBlueMatched) {
            return 3; // 三等奖
        } else if (matchedReds == 5 || (matchedReds == 4 && isBlueMatched)) {
            return 4; // 四等奖
        } else if (matchedReds == 4 || (matchedReds == 3 && isBlueMatched)) {
            return 5; // 五等奖
        } else if (isBlueMatched) {
            return 6; // 六等奖
        } else {
            return 0; // 未中奖
        }
    }

    private static Set<Integer> toSet(int[] balls) {
        Set<Integer> set = new HashSet<>();
        for (int ball : balls) {
            set.add(ball);
        }
        return set;
    }
}